package com.club.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web项目配置类
 *
 * @author chaochao(vx : zhangfec)
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {


    @Value("${clubImagesFilePath}")
    private String clubImagesFilePath;

    @Value("${acaterAccessPath}")
    private String acaterAccessPath;

    @Value("${avatarImagesFilePath}")
    private String avatarImagesFilePath;

    @Value("${clubAccessPath}")
    private String clubAccessPath;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .maxAge(3600);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/" + clubAccessPath + "**").addResourceLocations("file:" + clubImagesFilePath);
        registry.addResourceHandler("/" + acaterAccessPath + "**").addResourceLocations("file:" + avatarImagesFilePath);
    }

}
